package inits

import (
	"fmt"
	"go.uber.org/zap"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"weekly-exam/config"
	"weekly-exam/globar"
)

func InitMysql() {
	var err error
	data := config.ConappfigData.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", data.User, data.Password, data.Host, data.Port, data.DataBase)
	globar.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	log.Println("mysql is success")
	sufo, _ := zap.NewProduction()
	sufo.Info("mysql is success")
}
